<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="/resources/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/resources/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <script src="/resources/js/echarts.min.js"></script>
    <link rel="stylesheet" href="/resources/css/amazeui.min.css" />
    <link rel="stylesheet" href="/resources/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="/resources/css/app.css">
    <script src="/resources/js/jquery.min.js"></script>

</head>

<body data-type="widgets">

    <script src="/resources/js/theme.js"></script>

    <div class="am-g tpl-g">

        <%--头部开始--%>
        <%@include file="header.jsp" %>
        <%--头部结束--%>

        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">

                            <div class="container-fluid am-cf">
                                <div class="row">
                                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
                                        <div class="page-header-heading"><span class="am-icon-suitcase page-header-heading-icon"></span> 商品管理
                                            <small>Commodity management</small>
                                        </div>
                                        <p class="page-header-description">对商品信息进行增加、修改、删除、等操作。</p>
                                    </div>
                                    <div class="am-u-lg-3 tpl-index-settings-button">
                                        <%--<button type="button" class="page-header-button"><span class="am-icon-paint-brush"></span> 设置</button>--%>
                                    </div>
                                </div>
                            </div>

                            <div class="widget-body  am-fr">
                                <!-- 编辑栏 -->
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button type="button" class="am-btn am-btn-default am-btn-success" onclick="hideBtn();" data-am-modal="{target: '#productModel', width: 900}"><span class="am-icon-plus"></span> 新增商品</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- 右上角搜索框 -->
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select id="searchType" data-am-selected="{btnSize: 'sm'}">
                                            <option value="productNo">商品编号</option>
                                            <option value="proEffect">商品功效</option>
                                            <option value="proInstruct">商品说明</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="text" class="am-form-field" id="searchContent">
                                        <span class="am-input-group-btn">
                                            <button class="am-btn am-btn-default am-btn-success tpl-table-list-field am-icon-search" id="searchBtn" type="button"></button>
                                        </span>
                                    </div>
                                </div>

                                <!-- 表格显示 -->
                                <div class="am-u-sm-12">
                                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black" id="commodityForm">
                                        <thead>
                                            <tr>
                                                <th class="am-text-center">分类名称</th>
                                                <th class="am-text-center">商品编号</th>
                                                <th class="am-text-center">商品图片</th>
                                                <th class="am-text-center">商品名称</th>
                                                <th class="am-text-center">进货价格</th>
                                                <th class="am-text-center">进货日期</th>
                                                <th class="am-text-center">售价</th>
                                                <th class="am-text-center">库存</th>
                                                <th class="am-text-center">计量方式</th>
                                                <th class="am-text-center">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody class="am-text-center">
                                            <c:forEach items="${pageInfo.list }" var="p">
                                                <tr class="gradeX">
                                                    <td>${p.productType.typeName }</td>
                                                    <td>${p.product.productNo }</td>
                                                    <td>
                                                        <a href="#" onclick="showPhotoFun('${p.product.productId}');" data-am-modal="{target: '#showPictureModel', closeViaDimmer: 0, width: '600px', height: '500px'}">图片</a>
                                                    </td>
                                                    <td>${p.product.reserve1 }</td>
                                                    <td>￥${p.product.purchasePrice }</td>
                                                    <td>
                                                        ${fn:substring(p.product.purchaseDate, 0, 10)}
                                                    </td>
                                                    <td>￥${p.product.unitPrice }</td>
                                                    <td>${p.product.proStock }</td>
                                                    <td>${p.product.measureWay }</td>
                                                    <td>
                                                        <button type="button" class="am-btn am-btn-xs am-btn-secondary" onclick="editProductFun('${p.product.productId}')" data-am-modal="{target: '#productModel', width: 900}">
                                                            <span class="am-icon-eye"></span> 查看
                                                        </button>
                                                        <button type="button" class="am-btn am-btn-xs am-btn-danger" onclick="delProFun('${p.product.productId}')">
                                                            <span class="am-icon-trash-o"></span> 删除
                                                        </button>
                                                    </td>
                                                </tr>
                                            </c:forEach>
                                        </tbody>
                                    </table>
                                </div>

                                <%-- 分页开始 --%>
                                <div class="am-u-lg-12 am-cf">

                                    <!-- 分页文字信息，其中分页信息都封装在pageInfo中 -->
                                    <div class="col-md-6">
                                        当前第：${pageInfo.pageNum }页，总共：${pageInfo.pages }页，总共：${pageInfo.total }条记录
                                    </div>
                                    <div class="am-fr">
                                        <ul class="am-pagination tpl-pagination">
                                            <!-- 首页 -->
                                            <li><a href="/productController/searchProduct?pn=1&type=${type}&content=${content}">首页</a></li>
                                            <!-- 上一页 -->
                                            <c:if test="${pageInfo.hasPreviousPage }">
                                                <li>
                                                    <a href="/productController/searchProduct?pn=${pageInfo.pageNum-1 }&type=${type}&content=${content}" aria-label="Previous">
                                                        <span aria-hidden="true">&laquo;</span>
                                                    </a>
                                                </li>
                                            </c:if>
                                            <!-- 循环遍历连续显示的页面，若是当前页就高亮显示，并且没有链接 -->
                                            <c:forEach items="${pageInfo.navigatepageNums }" var="page_Num">
                                                <c:if test="${page_Num == pageInfo.pageNum }">
                                                    <li class="am-active"><a href="/productController/searchProduct?pn=${page_Num }&type=${type}&content=${content}">${page_Num }</a></li>
                                                </c:if>
                                                <c:if test="${page_Num != pageInfo.pageNum }">
                                                    <li><a href="/productController/searchProduct?pn=${page_Num }&type=${type}&content=${content}">${page_Num }</a></li>
                                                </c:if>
                                            </c:forEach>
                                            <!-- 下一页 -->
                                            <c:if test="${pageInfo.hasNextPage }">
                                                <li>
                                                    <a href="/productController/searchProduct?pn=${pageInfo.pageNum+1 }&type=${type}&content=${content}" aria-label="Next">
                                                        <span aria-hidden="true">&raquo;</span>
                                                    </a>
                                                </li>
                                            </c:if>
                                            <!-- 末页 -->
                                            <li><a href="/productController/searchProduct?pn=${pageInfo.pages }&type=${type}&content=${content}">末页</a></li>
                                        </ul>
                                    </div>
                                </div>
                                <!-- 分页结束 -->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 商品模态框开始 -->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="productModel">
        <div class="am-modal-dialog">
            <div class="am-modal-bd" style="padding: 1px;">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf" style="margin: 0;">
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl"><h2>商品管理表单</h2></div>
                                <div class="widget-function am-fr">
                                    <a href="javascript: void(0)" class="am-close am-close-spin clearForm">&times;</a>
                                </div>
                            </div>
                            <div class="widget-body am-fr">

                                <form class="am-form tpl-form-border-form tpl-form-border-br" id="productForm">

                                    <!-- 主键 -->
                                    <div class="am-form-group am-hide">
                                        <label class="am-u-sm-3 am-form-label">ID</label>
                                        <div class="am-u-sm-6">
                                            <input type="text"name="productId" class="am-form-field tpl-form-no-bg productId"/>
                                        </div>
                                        <div class="am-u-sm-3">
                                        </div>
                                    </div>

                                    <!-- 商品图片 -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">商品图片</label>
                                        <div class="am-u-sm-6">
                                            <div class="tpl-form-file-img">
                                                <img class="image" style="width: 410px; height: 250px;">
                                            </div>
                                            <br>
                                            <div class="am-form-group am-form-file">
                                                <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                                    <i class="am-icon-cloud-upload"></i> 上传图片
                                                </button>
                                                <input type="file" class="proPhotoFile">
                                                <%-- 用于保存存入的地址 --%>
                                                <input type="text" name="proPhoto" class="am-hide proPhoto">
                                            </div>
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipproPhoto">可修改图片！</small>
                                        </div>
                                    </div>

                                    <!-- 商品名称 -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">商品名称</label>
                                        <div class="am-u-sm-6">
                                            <input type="text"name="reserve1" class="am-form-field tpl-form-no-bg reserve1" placeholder="请输入商品名称"/>
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipreserve1">此项为必填项！</small>
                                        </div>
                                    </div>

                                    <!-- 分类名称id -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">分类名称</label>
                                        <div class="am-u-sm-6">
                                            <select name="proTypeId" class="proTypeId" data-am-selected>
                                                <%-- -------------------------------- --%>
                                            </select>
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipproTypeId"></small>
                                        </div>
                                    </div>

                                    <!-- 商品编号 -->
                                    <div class="am-form-group" id="productNo">
                                        <label class="am-u-sm-3 am-form-label">编号</label>
                                        <div class="am-u-sm-6">
                                            <input type="text"name="productNo" maxlength="11" class="am-form-field tpl-form-no-bg productNo" readonly placeholder="请输入商品编号"/>
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipproductNo">此项为必填项！</small>
                                        </div>
                                    </div>

                                    <!-- 进货价格 -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">进货价格</label>
                                        <div class="am-u-sm-6">
                                            <input type="text" name="purchasePrice" maxlength="9" class="am-form-field tpl-form-no-bg purchasePrice" placeholder="请输入进货价格，仅限于整数或小数" />
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tippurchasePrice">此项为必填项！</small>
                                        </div>
                                    </div>

                                    <!-- 售价 -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">售价</label>
                                        <div class="am-u-sm-6">
                                            <input type="text" name="unitPrice" maxlength="9" class="am-form-field tpl-form-no-bg unitPrice" placeholder="请输入售价，仅限于整数或小数" />
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipunitPrice">此项为必填项！</small>
                                        </div>
                                    </div>

                                    <!-- 库存 -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">库存</label>
                                        <div class="am-u-sm-6">
                                            <input type="text" name="proStock" maxlength="10" class="am-form-field tpl-form-no-bg proStock" placeholder="请输入库存，仅限整数" />
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipproStock">此项为必填项！</small>
                                        </div>
                                    </div>

                                    <!-- 计量方式 -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">计量方式</label>
                                        <div class="am-u-sm-6">
                                            <select name="measureWay" class="measureWay" data-am-selected>
                                                <option value="包">包</option>
                                                <option value="克">克</option>
                                                <option value="袋">袋</option>
                                                <option value="箱">箱</option>
                                                <option value="其他">其他</option>
                                            </select>
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipmeasureWay"></small>
                                        </div>
                                    </div>

                                    <!-- 进货日期 -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">进货日期</label>
                                        <div class="am-u-sm-6">
                                            <div class="am-input-group am-datepicker-date" data-am-datepicker="{format: 'yyyy-mm-dd', viewMode: 'years'}">
                                                <input type="text" class="am-form-field purchaseDate" name="purchaseDate" placeholder="请选择进货日期" readonly>
                                                <span class="am-input-group-btn am-datepicker-add-on">
                                                        <button class="am-btn am-btn-default" type="button">
                                                            <span class="am-icon-calendar"></span>
                                                        </button>
                                                    </span>
                                            </div>
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tippurchaseDate">此项为必填项！</small>
                                        </div>
                                    </div>

                                    <!-- 商品成分-->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">成分</label>
                                        <div class="am-u-sm-6">
                                            <textarea name="ingre" rows="5" maxlength="200" class="am-form-field tpl-form-no-bg ingre" placeholder="请输入商品成分，最多不超过200字"></textarea>
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipingre">此项为必填项！</small>
                                        </div>
                                    </div>

                                    <!-- 商品功效-->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">功效</label>
                                        <div class="am-u-sm-6">
                                            <textarea name="proEffect" rows="5" maxlength="200" class="am-form-field tpl-form-no-bg proEffect" placeholder="请输入商品功效，最多不超过200字"></textarea>
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipproEffect">此项为必填项！</small>
                                        </div>
                                    </div>

                                    <!-- 商品用途 -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">用途</label>
                                        <div class="am-u-sm-6">
                                            <textarea name="useOf" rows="5" maxlength="200" class="am-form-field tpl-form-no-bg useOf" placeholder="请输入商品用途，最多不超过200字"></textarea>
                                        </div>
                                        <div class="am-u-sm-3">
                                            <small class="tipuseOf">此项为必填项！</small>
                                        </div>
                                    </div>

                                    <!-- 商品说明 -->
                                    <div class="am-form-group">
                                        <label class="am-u-sm-3 am-form-label">说明</label>
                                        <div class="am-u-sm-6">
                                            <textarea name="proInstruct" rows="5" maxlength="200" class="am-form-field tpl-form-no-bg proInstruct" placeholder="请输入商品说明，最多不超过200字"></textarea>
                                        </div>
                                        <div class="am-u-sm-3">
                                        </div>
                                    </div>

                                    <!-- 按钮 -->
                                    <div class="am-form-group">
                                        <div class="am-u-sm-12">
                                            <button type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success clearForm"><i class="am-icon-close"></i> 关闭</button>
                                            <button type="button" class="am-btn am-btn-success tpl-btn-bg-color-success" id="submitForm"><i class="am-icon-floppy-o"></i> 提交</button>
                                            <button type="button" class="am-btn am-btn-success tpl-btn-bg-color-success" id="updateBtn" onclick="updateEmpFun();"><i class="am-icon-floppy-o"></i> 更新</button>
                                        </div>
                                    </div>

                                </form>

                            </div>
                        </div>
                    </div>
                </div>
                <!-- 整个表单结束 -->
            </div>
        </div>
    </div>
    <!-- 商品模态框结束 -->

    <!-- 查看图片模态框开始 -->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="showPictureModel">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">
                商品图片
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div class="am-modal-bd">
                <div class="tpl-form-file-img">
                    <img alt="未找到图片" class="imagePhoto" width="580px" height="440px">
                </div>
            </div>
        </div>
    </div>
    <!-- 查看图片模态框结束 -->

    <!-- 删除提示警告框开始 -->
    <div class="am-modal am-modal-confirm" tabindex="-1" id="delConfirm">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">删除警告</div>
            <div class="am-modal-bd">
                您，确定要删除这条记录吗？
            </div>
            <div class="am-modal-footer">
                <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                <span class="am-modal-btn" data-am-modal-confirm>确定</span>
            </div>
        </div>
    </div>
    <!-- 删除提示警告框结束 -->


    <script src="/resources/js/amazeui.min.js"></script>
    <script src="/resources/js/amazeui.datatables.min.js"></script>
    <script src="/resources/js/dataTables.responsive.min.js"></script>
    <script src="/resources/js/app.js"></script>
    <script src="/resources/jsutlis/fileutli.js"></script>
    <script src="/resources/js/product.form.validation.js"></script>

</body>
</html>